package com.deng.performance.second.view
{
	import com.deng.common.vo.EmployeeVo;
	import com.deng.event.ReturnEvent;
	
	import flash.events.KeyboardEvent;
	
	import mx.controls.Alert;
	import mx.controls.DataGrid;
	import mx.controls.TextInput;
	import mx.events.FlexEvent;
	import mx.resources.ResourceManager;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.RemoteObject;
	import mx.utils.StringUtil;

	public class Pay_GongZuoJiXiaoTI extends TextInput
	{
		private var pvo:EmployeeVo;
		public function Pay_GongZuoJiXiaoTI()
		{
			this.restrict = "0-9\.";
			this.width = 40;
			this.addEventListener(KeyboardEvent.KEY_UP,updateData);
			this.addEventListener(FlexEvent.CREATION_COMPLETE,showHandler);
			this.addEventListener(FlexEvent.SHOW,showHandler);
			super();
		}
		private function updateRst(evt:ResultEvent):void{
			new ReturnEvent(ReturnEvent.searchSecondOrganizationByUpdate).dispatch();
			Alert.show(ResourceManager.getInstance().getString("lang", "update_success"));
			this.data = pvo;
		}
		private function updateData(event:KeyboardEvent):void{
			if(event.keyCode == 13){
				if(isNaN(new Number(this.text))){
					Alert.show(ResourceManager.getInstance().getString("lang", "input_item_error"));
					return;
				}
				if(pvo.pay_gongzuojixiao == StringUtil.trim(this.text)){
					return;
				}
				pvo.pay_gongzuojixiao = StringUtil.trim(this.text);
				var ro:RemoteObject = new RemoteObject();
				ro.destination = "AdminBonusImpl";			
				ro.addEventListener(FaultEvent.FAULT,flt);
				ro.addEventListener(ResultEvent.RESULT,updateRst);
				ro.updatePayGongZuoJiXiao(pvo);
				
				(this.parent.parent as DataGrid).setFocus();				
			}
		}
		private function flt(evt:FaultEvent):void{
			Alert.show(" : "+evt.fault.getStackTrace());
		}
		private function showHandler(event:FlexEvent):void{
			pvo = this.data as EmployeeVo;
			if(pvo.pay_gongzuojixiao == null){
				this.text = "0";
			}else{
				this.text = pvo.pay_gongzuojixiao;
			}
			if(pvo.valid_gongzuojixiao == 1){
				this.enabled = false;
			}
		}
	}
}